﻿using System.Collections.Generic;
using MugenInjection.Xml.Interface;

namespace MugenInjection.Xml.Infrastructure
{
    /// <summary>
    /// Represents class for create <see cref="IXmlBindingBuilder"/> from <see cref="IXmlElement"/>.
    /// </summary>
    public class XmlBindingReader : IXmlBindingReader
    {
        #region Implementation of IXmlBindingReader

        /// <summary>
        /// Reads bindings from specified xml.
        /// </summary>
        /// <param name="xmlElement">The specified root of xml.</param>
        /// <param name="moduleName">A module name.</param>
        /// <returns>A series instances of <see cref="IXmlBindingBuilder"/>.</returns>
        public IList<IXmlBindingBuilder> ReadBindings(IXmlElement xmlElement, out string moduleName)
        {
            moduleName = xmlElement.GetAttribute(XmlLoaderUtils.BindingNameAttr);
            var result = new List<IXmlBindingBuilder>();
            foreach (IXmlElement element in xmlElement.GetNodes(XmlLoaderUtils.BindingElementName))
                result.Add(new XmlBindingBuilder(element));
            return result;
        }

        #endregion
    }
}